import mysql from "mysql";
import {
    rejects
} from "assert";
const pool = mysql.createPool({
    connectionLimit: 10,
    user: "root",
    password: "",
    database: "zouxiuba",
    port: 3306
})


//异步
function exec(sql, params, callback) {
    pool.getConnection((err, conn) => {
        conn.query(sql, params, callback);
        conn.release(); //释放连接
    })
}

function execSync(sql, params) {
    return new Promise((resolve, reject) => {

        pool.getConnection((err, conn) => {
            if (err) {
                reject(err.message);
                return;
            }
            conn.query(sql, params, (err, result, fidlds) => {
                if (err) {
                    reject(err.message);
                    return;
                }
                resolve(result, fidlds);
            })
        })
    })

}
module.exports = {
    exec,
    execSync
}